<template>
	<!-- 消費明細 -->
	<view class="container">
		<!-- <view class="time_select">
			<text>2023-07</text>
			<image src="/static/images/xiangxiajiantou.png"></image>
		</view> -->
		<!-- <uni-datetime-picker type="date" ></uni-datetime-picker> -->
		<picker mode="date" fields="month" @change="timeChange">
			<view class="time_select">
				<text>{{time}}</text>
				<image src="/static/images/xiangxiajiantou.png"></image>
			</view>
		</picker>



		<scroll-view class="scroll_y" scroll-y="true" @scrolltolower="scroll">
			<view class="list_item" v-for="item in consumeList" :key="item.id">
				<view class="left">
					<view style="font-size: 26rpx;">{{item.desc}}</view>
					<!-- <view style="font-size: 20rpx;margin: 10rpx 0;">訂單編號</view> -->
					<view style="font-size: 20rpx;">{{effectiveTime(item.create_time*1000)}}</view>
				</view>
				<view class="right" style="color: #FA533D;font-size: 26rpx;font-weight: bold;" v-if="item.type==2">
					-{{item.num}}</view>
				<view class="right" style="color: #39B19D;font-size: 26rpx;font-weight: bold;" v-if="item.type==4">
					+{{item.num}}</view>
			</view>
		</scroll-view>

	</view>
</template>

<script>
	import {
		getUserConsumeList
	} from '@/api/me.js'
	export default {
		data() {
			return {
				time: "",
				page: 1,
				consumeList: [],
				flag: true
			};
		},
		methods: {
			timeChange: function(e) {
				this.time = e.detail.value
				console.log(this.time)

				getUserConsumeList({
					page: 1,
					month: this.time,
				}).then(res => {
					this.consumeList = res.data
				})
			},
			scroll() {
				if (this.flag) {
					getUserConsumeList({
						page: ++this.page,
						month: this.time
					}).then(res => {
						// console.log(res.data,"消費明細")
						if (res.data.length) {
							this.consumeList = this.consumeList.concat(res.data)
						} else {
							this.flag = false
						}

					})
				}
			},
			effectiveTime(num) {
				let time = new Date(num)
				let y = time.getFullYear()
				let m = time.getMonth() + 1 >= 10 ? time.getMonth() + 1 : "0" + (time.getMonth() + 1)
				let d = time.getDate() >= 10 ? time.getDate() : "0" + (time.getDate())
				let h = time.getHours() >= 10 ? time.getHours() : "0" + (time.getHours())
				let n = time.getMinutes() >= 10 ? time.getMinutes() : "0" + (time.getMinutes())
				return y + "-" + m + "-" + d + " " + h + ":" + n
			},
		},
		onLoad() {
			var date = new Date()
			var month = date.getMonth() + 1 >= 10 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1)
			// console.log(date.getFullYear(), month)
			this.time = date.getFullYear() + "-" + month

			getUserConsumeList({
				page: 1,
				month: this.time,
			}).then(res => {
				// console.log(res.data,"消費明細")
				this.consumeList = res.data
			})

		},
	}
</script>

<style lang="less">
	.container {
		height: calc(100vh - 90rpx);
		background: #F3F5F9;
		padding: 14rpx 31rpx;
		box-sizing: border-box;

		.time_select {
			width: 191rpx;
			height: 50rpx;
			background: #F8FDFB;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			border: 1rpx solid #39B19D;
			font-size: 28rpx;
			color: #39B19D;
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin-bottom: 30rpx;

			image {
				width: 30rpx;
				height: 30rpx;
			}
		}

		.scroll_y {
			// height: 100rpx;
			background: #fff;
			border-radius: 16rpx;
			padding: 25rpx 30rpx;
			box-sizing: border-box;
			height: 85vh;

			.list_item {
				display: flex;
				justify-content: space-between;
				padding-bottom: 20rpx;
				border-bottom: 1rpx solid #F2F2F2;
				margin-bottom: 30rpx;
			}
		}

	}
</style>